package com.rabbitmq.demo.dmp;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;

import java.nio.charset.StandardCharsets;
import java.util.Date;

public class Sender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Scheduled(fixedDelay = 1000, initialDelay = 500)
    public void send(){
        Message message = MessageBuilder.withBody(("Hello! " + new Date()).getBytes()).setHeader("x-delay", 5000).build();
        rabbitTemplate.send("delayed.message.exchange","delayed.queue",message);
    }
}
